import pandas
from scipy.stats import pearsonr
# import numpy as np
# from scipy.stats import chi2_contingency

from data_structures.coefficientOfAssociation import CoefficientOfAssociation

if __name__ == '__main__':
    # 1. 自己写
    # 读取CSV文件
    df = pandas.read_csv('../data/data2_4.csv', encoding='utf-8')

    # 筛选列
    column_age = df['age']
    column_fat = df['%fat']

    coefficientOfAssociation = CoefficientOfAssociation(column_age, column_fat)

    # 打印皮尔逊相关系数
    r = coefficientOfAssociation.pearson_correlation_coefficient()
    print(f'皮尔逊相关系数r = {r}')

    # # 打印卡方值
    # chi_square_value = coefficientOfAssociation.chi_square_test()
    # print(f'卡方值 = {chi_square_value}')

    # 2. 调包
    # 计算皮尔逊相关系数
    corr = pearsonr(column_age, column_fat)[0]
    print(f"皮尔逊相关系数为: {round(corr, 5)}")

    # # 假设这是你的二维数据，表示两个分类变量的频数
    # data = np.array([column_age,  # 第一类的频数
    #                  column_fat])  # 第二类的频数
    #
    # # 计算卡方值和p值
    # chi2, p, dof, expected = chi2_contingency(data)
    #
    # print(f"卡方值为：{chi2}")
